package com.itheima.service.Impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;

    /**
     * 柱状图
     * 将Mapper层返回的List集合拆分为JobOption的两个属性并赋值
     * @return
     */
    @Override
    public JobOption getEmpJobData() {
        JobOption jobOption = new JobOption();
        List<Map<String,Object>> listMap =  reportMapper.selectEmpJobData();//List类型数组，存放的是Map类型的对象，每个Map都有两个数据
        List<Object> jobList = listMap.stream().map(map -> map.get("job")).collect(Collectors.toList());//get方法，通过key获取value
        List<Object> count = listMap.stream().map(map -> map.get("count")).collect(Collectors.toList());
        jobOption.setJobList(jobList);
        jobOption.setDataList(count);
        return jobOption;
    }

    @Override
    public List<Map> getEmpGenderData() {

        return reportMapper.getEmpGenderData();
    }

    @Override
    public List<Map> getstudentDegreeData() {
        return reportMapper.selectStudentDegree();
    }

    @Override
    public StudentOption getStudentCount() {
        StudentOption studentOption = new StudentOption();
        List<Map<String,Object>> studentMap =reportMapper.selectStudentCount();
        List<Object> clazzList = studentMap.stream().map(map -> map.get("clazzList")).collect(Collectors.toList());
        List<Object> dataList = studentMap.stream().map(map -> map.get("dataList")).collect(Collectors.toList());
        studentOption.setClazzList(clazzList);
        studentOption.setDataList(dataList);
        return studentOption;
    }
}
